<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <base href="<%=request.getContextPath()%>/">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑科室</title>
    <link rel="stylesheet" href="statics/css/hisStyle.css">
    <link rel="stylesheet" href="statics/css/common-styles.css">
</head>
<body>
<%@include file="../common/sidebar.jsp"%>
<div class="main-content">
    <%@include file="../common/top.jsp"%>
    <div class="content">
        <div class="card">
            <h2 class="section-title">编辑科室</h2>
            <c:if test="${not empty errorMessage}">
                <div class="message error-message">${errorMessage}</div>
            </c:if>
            <form action="department/modify" method="post">
                <!-- 隐藏域传递科室ID -->
                <input type="hidden" name="deptid" id="deptid" value="${department.deptid}"/>
                <div class="form-group">
                    <label for="hospitalid" class="required">所属医院：</label>
                    <select id="hospitalid" name="hospitalid" class="form-control" required>
                        <option value="">-- 请选择医院 --</option>
                        <c:forEach items="${hospitalList}" var="hospital">
                            <option value="${hospital.hospitalId}"
                                    <c:if test="${department.hospitalId eq hospital.hospitalId}">selected</c:if>>
                                ${hospital.hospitalName}
                            </option>
                        </c:forEach>
                    </select>
                </div>
                <div class="form-group">
                    <label for="deptname" class="required">科室名称：</label>
                    <select id="deptname" name="deptname" class="form-control" required>
                        <option value="">-- 请选择科室 --</option>
                        <option value="内科" <c:if test="${department.deptname eq '内科'}">selected</c:if>>内科</option>
                        <option value="心内科" <c:if test="${department.deptname eq '心内科'}">selected</c:if>>心内科</option>
                        <option value="消化内科" <c:if test="${department.deptname eq '消化内科'}">selected</c:if>>消化内科</option>
                        <option value="呼吸内科" <c:if test="${department.deptname eq '呼吸内科'}">selected</c:if>>呼吸内科</option>
                        <option value="神经内科" <c:if test="${department.deptname eq '神经内科'}">selected</c:if>>神经内科</option>
                        <option value="内分泌科" <c:if test="${department.deptname eq '内分泌科'}">selected</c:if>>内分泌科</option>
                        <option value="肾内科" <c:if test="${department.deptname eq '肾内科'}">selected</c:if>>肾内科</option>
                        <option value="血液内科" <c:if test="${department.deptname eq '血液内科'}">selected</c:if>>血液内科</option>
                        <option value="风湿免疫科" <c:if test="${department.deptname eq '风湿免疫科'}">selected</c:if>>风湿免疫科</option>
                        <option value="感染科" <c:if test="${department.deptname eq '感染科'}">selected</c:if>>感染科</option>
                        <option value="外科" <c:if test="${department.deptname eq '外科'}">selected</c:if>>外科</option>
                        <option value="普通外科" <c:if test="${department.deptname eq '普通外科'}">selected</c:if>>普通外科</option>
                        <option value="肝胆外科" <c:if test="${department.deptname eq '肝胆外科'}">selected</c:if>>肝胆外科</option>
                        <option value="神经外科" <c:if test="${department.deptname eq '神经外科'}">selected</c:if>>神经外科</option>
                        <option value="胸外科" <c:if test="${department.deptname eq '胸外科'}">selected</c:if>>胸外科</option>
                        <option value="心外科" <c:if test="${department.deptname eq '心外科'}">selected</c:if>>心外科</option>
                        <option value="泌尿外科" <c:if test="${department.deptname eq '泌尿外科'}">selected</c:if>>泌尿外科</option>
                        <option value="骨科" <c:if test="${department.deptname eq '骨科'}">selected</c:if>>骨科</option>
                        <option value="整形外科" <c:if test="${department.deptname eq '整形外科'}">selected</c:if>>整形外科</option>
                        <option value="烧伤科" <c:if test="${department.deptname eq '烧伤科'}">selected</c:if>>烧伤科</option>
                        <option value="妇产科" <c:if test="${department.deptname eq '妇产科'}">selected</c:if>>妇产科</option>
                        <option value="产科" <c:if test="${department.deptname eq '产科'}">selected</c:if>>产科</option>
                        <option value="妇科" <c:if test="${department.deptname eq '妇科'}">selected</c:if>>妇科</option>
                        <option value="儿科" <c:if test="${department.deptname eq '儿科'}">selected</c:if>>儿科</option>
                        <option value="新生儿科" <c:if test="${department.deptname eq '新生儿科'}">selected</c:if>>新生儿科</option>
                        <option value="眼科" <c:if test="${department.deptname eq '眼科'}">selected</c:if>>眼科</option>
                        <option value="耳鼻喉科" <c:if test="${department.deptname eq '耳鼻喉科'}">selected</c:if>>耳鼻喉科</option>
                        <option value="口腔科" <c:if test="${department.deptname eq '口腔科'}">selected</c:if>>口腔科</option>
                        <option value="皮肤科" <c:if test="${department.deptname eq '皮肤科'}">selected</c:if>>皮肤科</option>
                        <option value="精神心理科" <c:if test="${department.deptname eq '精神心理科'}">selected</c:if>>精神心理科</option>
                        <option value="中医科" <c:if test="${department.deptname eq '中医科'}">selected</c:if>>中医科</option>
                        <option value="中医内科" <c:if test="${department.deptname eq '中医内科'}">selected</c:if>>中医内科</option>
                        <option value="中医外科" <c:if test="${department.deptname eq '中医外科'}">selected</c:if>>中医外科</option>
                        <option value="针灸推拿科" <c:if test="${department.deptname eq '针灸推拿科'}">selected</c:if>>针灸推拿科</option>
                        <option value="康复医学科" <c:if test="${department.deptname eq '康复医学科'}">selected</c:if>>康复医学科</option>
                        <option value="麻醉科" <c:if test="${department.deptname eq '麻醉科'}">selected</c:if>>麻醉科</option>
                        <option value="急诊科" <c:if test="${department.deptname eq '急诊科'}">selected</c:if>>急诊科</option>
                        <option value="重症医学科" <c:if test="${department.deptname eq '重症医学科'}">selected</c:if>>重症医学科</option>
                        <option value="病理科" <c:if test="${department.deptname eq '病理科'}">selected</c:if>>病理科</option>
                        <option value="检验科" <c:if test="${department.deptname eq '检验科'}">selected</c:if>>检验科</option>
                        <option value="医学影像科" <c:if test="${department.deptname eq '医学影像科'}">selected</c:if>>医学影像科</option>
                        <option value="超声科" <c:if test="${department.deptname eq '超声科'}">selected</c:if>>超声科</option>
                        <option value="核医学科" <c:if test="${department.deptname eq '核医学科'}">selected</c:if>>核医学科</option>
                        <option value="药剂科" <c:if test="${department.deptname eq '药剂科'}">selected</c:if>>药剂科</option>
                        <option value="预防保健科" <c:if test="${department.deptname eq '预防保健科'}">selected</c:if>>预防保健科</option>
                        <option value="营养科" <c:if test="${department.deptname eq '营养科'}">selected</c:if>>营养科</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="illness">诊疗范围：</label>
                    <textarea id="illness" name="illness" class="form-control" rows="3">${department.illness}</textarea>
                </div>
                <div class="form-group">
                    <label for="equipment">设备配置：</label>
                    <textarea id="equipment" name="equipment" class="form-control" rows="3">${department.equipment}</textarea>
                </div>
                <div class="form-actions">
                    <button type="submit" class="btn btn-primary">保存修改</button>
                    <button type="button" class="btn btn-secondary" onclick="window.location.href='department/find'">返回列表</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        // 表单验证
        const form = document.querySelector('form');
        form.addEventListener('submit', function(event) {
            const deptname = document.getElementById('deptname').value;
            const hospitalid = document.getElementById('hospitalid').value;
            
            let isValid = true;
            let errorMsg = '';
            
            if (!deptname) {
                isValid = false;
                errorMsg = '科室名称不能为空';
            } else if (!hospitalid) {
                isValid = false;
                errorMsg = '请选择所属医院';
            }
            
            if (!isValid) {
                alert(errorMsg);
                event.preventDefault();
            }
        });
    });
</script>

</body>
</html>